﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.Model;


namespace AnyOffice.general.calendar.manage
{
    public partial class query : ModulePage
    {
     
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                this.litNavTitle.Text = "日程安排查询 ";
            }
            if (this.Page.IsPostBack)
            {
                this.litNavTitle.Text = "日程安排查询结果";
                this.pnlMain.Visible = false;
                this.pnlLater.Visible = true;
                SqlCommand command = new SqlCommand();
                base.Conn.Open();
                command.Connection = base.Conn;
                string str = "SELECT *,dbo.GetUserName([ManagerId]) AS ManagerUserName FROM [Calendar] WHERE [UserId] = '" + base.User.Identity.Name + "' ";
                if (this.selectCalType.Value != string.Empty)
                {
                    str = str + " AND CalType = @CalType ";
                    command.Parameters.Add("@CalType", Convert.ToInt32(this.selectCalType.Value));
                }
                if (this.txtSendTimeMIN.Value != string.Empty)
                {
                    str = str + " AND StartTime >= @MinDate ";
                    command.Parameters.Add("@MinDate", Convert.ToDateTime(this.txtSendTimeMIN.Value + " 00:00:00"));
                }
                if (this.txtSendTimeMAX.Value != string.Empty)
                {
                    str = str + " AND StartTime <= @MaxDate ";
                    command.Parameters.Add("@MaxDate", Convert.ToDateTime(this.txtSendTimeMAX.Value + " 23:59:59"));
                }
                if (this.txtContent.Value != string.Empty)
                {
                    str = str + " AND Content LIKE '%' + @Content + '%' ";
                    command.Parameters.Add("@Content", this.txtContent.Value);
                }
                str = str + " ORDER BY StartTime DESC";
                command.CommandText = str;
                SqlDataReader reader = command.ExecuteReader();
                if (reader.HasRows)
                {
                    this.rptCalendar.DataSource = reader;
                    this.rptCalendar.DataBind();
                }
                else
                {
                    this.litMessage.Text = base.ShowMessage("无符合条件的日程安排");
                }
            }
        } 

    }
}
